//
//  YSY_HeroIntroduce_ViewController.m
//  GoodManNews
//
//  Created by dllo on 16/1/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YSY_HeroIntroduce_ViewController.h"
#import "YSY_Game_HeroDetailModel.h"
#import "YSY_HeroRelation_TableViewCell.h"
#import "YSY_HeroDetail_ViewController.h"
#define HEROHEADIMAGE(heroName) [NSString stringWithFormat:@"http://img.lolbox.duowan.com/champions/%@_120x120.jpg", heroName]
@interface YSY_HeroIntroduce_ViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation YSY_HeroIntroduce_ViewController
- (void)dealloc
{
    self.myTableV.delegate = nil;
    self.myTableV.dataSource = nil;
    
    [_myTableV release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
}

#pragma mark - 私有办法
- (void)createView {
    self.myTableV = [UITableView new];
    [self.view addSubview:self.myTableV];
    [self.myTableV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    self.myTableV.delegate = self;
    self.myTableV.dataSource = self;
    
    [self.myTableV registerClass:[YSY_HeroRelation_TableViewCell class] forCellReuseIdentifier:@"heroRelationCell"];
    [self.myTableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    
    
}
#pragma mark - 协议方法

//区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}
//区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}
//区  行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger number ;
    switch (section) {
        case 0:
            
            
        case 1:
            number = 2;
            break;
        case 2:
            
            
        case 3:
            number = 1;
            break;
        default:
            break;
    }
    return number;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height ;
    switch (indexPath.section) {
        case 0:
            if (0 == indexPath.row) {
                CGFloat strHeight = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.like[0][@"des"] width:(WIDTH - 2 * PAD) / 3 * 2];
                if (strHeight > (WIDTH - 2 * PAD) / 3) {
                    height = strHeight;
                }else {
                    height = (WIDTH - 2 * PAD) / 3;
                }
                
            }else {
                CGFloat strHeight = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.like[1][@"des"] width:(WIDTH - 2 * PAD) / 3 * 2];
                if (strHeight > (WIDTH - 2 * PAD) / 3) {
                    height = strHeight;
                }else {
                    height = (WIDTH - 2 * PAD) / 3;
                }
                
            }
            
            
            break;
        case 1:
            if (0 == indexPath.row) {
                CGFloat strHeight = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.hate[0][@"des"] width:(WIDTH - 2 * PAD) / 3 * 2];
                if (strHeight > (WIDTH - 2 * PAD) / 3) {
                    height = strHeight;
                }else {
                    height = (WIDTH - 2 * PAD) / 3;
                }
                
            }else {
                CGFloat strHeight = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.hate[1][@"des"] width:(WIDTH - 2 * PAD) / 3 * 2];
                if (strHeight > (WIDTH - 2 * PAD) / 3) {
                    height = strHeight;
                }else {
                    height = (WIDTH - 2 * PAD) / 3;
                }
            }
            break;
        case 2:
            height = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.tips width:WIDTH - 2 * PAD];
            break;
        case 3:
            height = [YSY_HeroRelation_TableViewCell stringHeight:self.heroModel.opponentTips width:WIDTH - 2 * PAD];
            break;
            
        default:
            break;
    }
    return height;
}
//铺cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    switch (indexPath.section) {
        case 0:
        {
            YSY_HeroRelation_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"heroRelationCell"];
            if (0 == indexPath.row) {
                [cell.headImageV sd_setImageWithURL:[NSURL URLWithString:HEROHEADIMAGE(self.heroModel.like[0][@"partner"])] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
                cell.heroIntroduceL.numberOfLines = 0;
                cell.heroIntroduceL.text = self.heroModel.like[0][@"des"];
            }else {
                [cell.headImageV sd_setImageWithURL:[NSURL URLWithString:HEROHEADIMAGE(self.heroModel.like[1][@"partner"])] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
                cell.heroIntroduceL.numberOfLines = 0;
                cell.heroIntroduceL.text = self.heroModel.like[1][@"des"];
            }
            return cell;
        }
            break;
        case 1:
        {
            YSY_HeroRelation_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"heroRelationCell"];
            if (0 == indexPath.row) {
                [cell.headImageV sd_setImageWithURL:[NSURL URLWithString:HEROHEADIMAGE(self.heroModel.hate[0][@"partner"])] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
                cell.heroIntroduceL.text = self.heroModel.hate[0][@"des"];
            }else {
                [cell.headImageV sd_setImageWithURL:[NSURL URLWithString:HEROHEADIMAGE(self.heroModel.hate[1][@"partner"])] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
                cell.heroIntroduceL.text = self.heroModel.hate[1][@"des"];
            }
            return cell;
        }
            break;
        case 2:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
            cell.textLabel.numberOfLines = 0;
            cell.textLabel.text = self.heroModel.tips;
            return cell;
        }
            break;
        case 3:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
            cell.textLabel.numberOfLines = 0;
            cell.textLabel.text = self.heroModel.opponentTips;
            return cell;
        }
            break;
            
        default:
            return nil;
            break;
    }
    
}
//区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [UIView new];
    headView.frame = CGRectMake(0, 0, WIDTH, 50);
    headView.backgroundColor = [UIColor grayColor];
    UILabel *title = [UILabel new];
    [headView addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(headView);
    }];
    switch (section) {
        case 0:
            title.text = @"1.最佳搭档";
            break;
        case 1:
            title.text = @"2.被谁克制";
            break;
        case 2:
            title.text = @"3.使用技巧";
            break;
        case 3:
            title.text = @"4.对抗技巧";
            break;
        default:
            break;
    }
    return headView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.section) {
        
        if (0 == indexPath.row) {
            [self.delegata jumpToHeroDetail:self.heroModel.like[0][@"partner"] cnName:nil];
            
        }else {
            [self.delegata jumpToHeroDetail:self.heroModel.like[1][@"partner"] cnName:nil];
        }

    }
    if (1 == indexPath.section) {
        
        
        if (0 == indexPath.row) {
            [self.delegata jumpToHeroDetail:self.heroModel.hate[0][@"partner"] cnName:nil];
            
        }else {
            [self.delegata jumpToHeroDetail:self.heroModel.hate[1][@"partner"] cnName:nil];
            
        }
        
    }
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
